<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Compressed Pair</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Utility">
<link rel="up" href="../utilities.html" title="Utilities">
<link rel="prev" href="../../boost/call_traits_T___idm2906.html" title="Struct template call_traits&lt;T &amp;&gt;">
<link rel="next" href="../../boost/compressed_pair.html" title="Class template compressed_pair">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../boost/call_traits_T___idm2906.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost/compressed_pair.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility.utilities.compressed_pair"></a><a class="link" href="compressed_pair.html" title="Compressed Pair">Compressed Pair</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="compressed_pair.html#utility.utilities.compressed_pair.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="compressed_pair.html#utility.utilities.compressed_pair.synopsis">Synopsis</a></span></dt>
<dt><span class="section"><a href="compressed_pair.html#compressed_pair.reference">Reference</a></span></dt>
<dt><span class="section"><a href="compressed_pair.html#utility.utilities.compressed_pair.acknowledgments">Acknowledgments</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.compressed_pair.introduction"></a><a class="link" href="compressed_pair.html#utility.utilities.compressed_pair.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<p>
          All of the contents of <a href="../../../../../../boost/compressed_pair.hpp" target="_top"><code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">compressed_pair</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a> are defined inside <code class="computeroutput"><span class="keyword">namespace</span> <span class="identifier">boost</span></code>.
        </p>
<p>
          The class <a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair"><code class="computeroutput"><span class="identifier">compressed_pair</span></code></a>
          is very similar to <a href="https://en.cppreference.com/w/cpp/utility/pair" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code></a>. However, if either of the
          template arguments are empty classes, then the <a href="https://en.cppreference.com/w/cpp/language/ebo" target="_top"><span class="emphasis"><em>empty
          base-class optimisation</em></span></a> is applied to compress the size
          of the pair.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.compressed_pair.synopsis"></a><a class="link" href="compressed_pair.html#utility.utilities.compressed_pair.synopsis" title="Synopsis">Synopsis</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">cpp</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<span class="keyword">class</span> <a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair"><code class="computeroutput"><span class="identifier">compressed_pair</span></code></a>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
    <span class="keyword">typedef</span> <span class="identifier">T1</span>                                                 <span class="identifier">first_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">T2</span>                                                 <span class="identifier">second_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">first_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span>       <span class="identifier">first_param_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">second_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span>      <span class="identifier">second_param_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">first_type</span><span class="special">&gt;::</span><span class="identifier">reference</span>        <span class="identifier">first_reference</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">second_type</span><span class="special">&gt;::</span><span class="identifier">reference</span>       <span class="identifier">second_reference</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">first_type</span><span class="special">&gt;::</span><span class="identifier">const_reference</span>  <span class="identifier">first_const_reference</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">second_type</span><span class="special">&gt;::</span><span class="identifier">const_reference</span> <span class="identifier">second_const_reference</span><span class="special">;</span>

             <span class="identifier">compressed_pair</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">base</span><span class="special">()</span> <span class="special">{}</span>
             <span class="identifier">compressed_pair</span><span class="special">(</span><span class="identifier">first_param_type</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">second_param_type</span> <span class="identifier">y</span><span class="special">);</span>
    <span class="keyword">explicit</span> <span class="identifier">compressed_pair</span><span class="special">(</span><span class="identifier">first_param_type</span> <span class="identifier">x</span><span class="special">);</span>
    <span class="keyword">explicit</span> <span class="identifier">compressed_pair</span><span class="special">(</span><span class="identifier">second_param_type</span> <span class="identifier">y</span><span class="special">);</span>

    <span class="identifier">compressed_pair</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">compressed_pair</span><span class="special">&amp;);</span>

    <span class="identifier">first_reference</span>       <span class="identifier">first</span><span class="special">();</span>
    <span class="identifier">first_const_reference</span> <span class="identifier">first</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>

    <span class="identifier">second_reference</span>       <span class="identifier">second</span><span class="special">();</span>
    <span class="identifier">second_const_reference</span> <span class="identifier">second</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>

    <span class="keyword">void</span> <span class="identifier">swap</span><span class="special">(</span><span class="identifier">compressed_pair</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">);</span>
<span class="special">};</span>
</pre>
<p>
          The two members of the pair can be accessed using the member functions
          <code class="computeroutput"><span class="identifier">first</span><span class="special">()</span></code>
          and <code class="computeroutput"><span class="identifier">second</span><span class="special">()</span></code>.
          Note that not all member functions can be instantiated for all template
          parameter types. In particular <a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair"><code class="computeroutput"><span class="identifier">compressed_pair</span></code></a> can be instantiated
          for reference and array types, however in these cases the range of constructors
          that can be used is limited. If types <code class="computeroutput"><span class="identifier">T1</span></code>
          and <code class="computeroutput"><span class="identifier">T2</span></code> are the same type,
          then there is only one version of the single-argument constructor, and
          this constructor initialises both values in the pair to the passed value.
        </p>
<p>
          Note that if either member is a <a href="https://en.cppreference.com/w/cpp/named_req/PODType" target="_top">POD</a>
          type, then that member is not zero-initialized by the <a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair"><code class="computeroutput"><span class="identifier">compressed_pair</span></code></a> default constructor:
          it is up to you to supply an initial value for these types if you want
          them to have a default value.
        </p>
<p>
          Note that <a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair"><code class="computeroutput"><span class="identifier">compressed_pair</span></code></a>
          can not be instantiated if either of the template arguments is a union
          type, unless there is compiler support for <a href="../../../../../../libs/type_traits/index.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_union</span></code></a>, or if <a href="../../../../../../libs/type_traits/index.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_union</span></code></a> is specialised for the
          union type.
        </p>
<p>
          Finally, a word of caution for Visual C++ 6 users: if either argument is
          an empty type, then assigning to that member will produce memory corruption,
          unless the empty type has a "do nothing" assignment operator
          defined. This is due to a bug in the way VC6 generates implicit assignment
          operators.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="compressed_pair.reference"></a>Reference</h4></div></div></div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="header.boost.detail.compressed_pair_hpp"></a>Header &lt;<a href="../../../../../../boost/detail/compressed_pair.hpp" target="_top">boost/detail/compressed_pair.hpp</a>&gt;</h5></div></div></div>
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">&gt;</span> <span class="keyword">class</span> <a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair">compressed_pair</a><span class="special">;</span>

  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="keyword">class</span> <a class="link" href="../../boost/compressed_pair_T__idm3185.html" title="Class template compressed_pair&lt;T, T&gt;">compressed_pair</a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&gt;</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">&gt;</span> 
    <span class="keyword">void</span> <a name="boost.swap_idm3230"></a><span class="identifier">swap</span><span class="special">(</span><a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair">compressed_pair</a><span class="special">&lt;</span> <span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span> <span class="special">&gt;</span> <span class="special">&amp;</span> x<span class="special">,</span> <a class="link" href="../../boost/compressed_pair.html" title="Class template compressed_pair">compressed_pair</a><span class="special">&lt;</span> <span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span> <span class="special">&gt;</span> <span class="special">&amp;</span> y<span class="special">)</span><span class="special">;</span>
<span class="special">}</span></pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.compressed_pair.acknowledgments"></a><a class="link" href="compressed_pair.html#utility.utilities.compressed_pair.acknowledgments" title="Acknowledgments">Acknowledgments</a>
</h4></div></div></div>
<p>
          Based on contributions by Steve Cleary, Beman Dawes, Howard Hinnant and
          John Maddock.
        </p>
<p>
          Maintained by <a href="mailto:john%40johnmaddock.co.uk" target="_top">John Maddock</a>.
        </p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001 Beman Dawes<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../boost/call_traits_T___idm2906.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost/compressed_pair.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
